<script setup>
import { ref } from 'vue';
import { ElMessage } from 'element-plus';
import { useIuserInfoStore } from '@T2/store/users.ts';
// import UnitByPosition from '@T2/views/Project/Manage/components/select/unitByPosition.vue';
import UnitByPosition from '@T2/views/Project/Display/components/select/unitByPosition.vue';
import ZutaiShow from '@T2/components/zutaiShow/index.vue';

const iuserInfoStore = useIuserInfoStore();
const { getHandleRight } = iuserInfoStore;
const RIGHT = getHandleRight(['325']);

const dftPage = ref(null);
const showUnitSelect = ref(false);
const unitlistChange = (data) => {
  showUnitSelect.value = data.length > 1 ? true : false;
}
const unitChange = (data, node) => {
  if (!data.params) {
    dftPage.value = null;
    ElMessage.error('该站点未关联组态页面');
    return;
  }
  const paramsObj = JSON.parse(data.params);
  const [ others0 ] = paramsObj?.others || [];
  const [ others00 ] = others0?.c || [];
  if (!others00) {
    dftPage.value = null;
    ElMessage.error('该站点未关联组态页面');
    return;
  }
  if (others00.t === 'zt' && others00.v) {
    dftPage.value = others00.v;
  } else {
    dftPage.value = null;
    ElMessage.error('该站点未关联组态页面');
  }
}
</script>

<template>
  <div id="menu_zt_container">
    <ZutaiShow
      :dftPage="dftPage"
      :showFunc="true"
      :disabled="!RIGHT['325']"
      v-if="dftPage"
    />
    <div class="units-select" v-show="showUnitSelect">
      <UnitByPosition @current-change="unitChange" @unitlist-change="unitlistChange" />
    </div>
  </div>
</template>

<style lang="scss" scoped>
#menu_zt_container {
  width: 100%;
  height: 100%;
  position: relative;
}
.units-select {
  width: 250px;
  position: absolute;
  top: 30px;
  left: 10px;
}
</style>